package phidgetmotion.phidget;

import com.phidgets.AccelerometerPhidget;
import com.phidgets.PhidgetException;
import com.phidgets.event.AccelerationChangeListener;
import com.phidgets.event.AttachListener;
import com.phidgets.event.DetachListener;
import com.phidgets.event.ErrorListener;

public class Accelerometer {

	private static AccelerometerPhidget accel;
	
	public static void init() throws PhidgetException {
		accel = new AccelerometerPhidget();
		accel.openAny();
	}
	
	public static void close() throws PhidgetException {
		accel.close();
		accel = null;
	}
	
	public static boolean isConnected(){
		try {
			return accel.isAttached();
		} catch (PhidgetException e) {
			return false;
		}
	}
	
	public static void addAttachListener(AttachListener attachListener){
		accel.addAttachListener(attachListener);
	}
	
	public static void addDetachListener(DetachListener detachListener){
		accel.addDetachListener(detachListener);
	}
	
	public static void addErrorListener(ErrorListener errorListener){
		accel.addErrorListener(errorListener);
	}
	
	public static void addAccelerationChangeListener(AccelerationChangeListener changeListener){
		accel.addAccelerationChangeListener(changeListener);
	}
	
	public static void removeAttachListener(AttachListener attachListener){
		accel.removeAttachListener(attachListener);
	}
	
	public static void removeDetachListener(DetachListener detachListener){
		accel.removeDetachListener(detachListener);
	}
	
	public static void removeErrorListener(ErrorListener errorListener){
		accel.removeErrorListener(errorListener);
	}
	
	public static void removeAccelerationChangeListener(AccelerationChangeListener changeListener){
		accel.removeAccelerationChangeListener(changeListener);
	}
}
